package com.example.tab02;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.fragment.AddFragment;

import java.util.List;

/**
 * Created by user on 2017-07-26.
 */
public  class  myRecycleradatper extends RecyclerView.Adapter<myRecycleradatper.MyViewHolder> {
    private  List<filelist> mDatas;
    private  Context mContext;
    private  LayoutInflater inflater;
    private OnItemClickListener listener;

    public  myRecycleradatper(Context context, List<filelist> datas){
        this.mContext=context;
        this.mDatas=datas;
        inflater=LayoutInflater.from (mContext);
    }

    @Override
    public  int  getItemCount() {
        return  mDatas.size();
    }
    @Override
    public  MyViewHolder onCreateViewHolder(ViewGroup parent,  int  viewType) {

        View view = inflater.inflate(R.layout.item_view,parent,  false );
        MyViewHolder holder=  new  MyViewHolder(view);
        holder.v.setBackgroundColor(Color.WHITE);
        return  holder;
    }

    @Override
    public  void  onBindViewHolder(MyViewHolder holder, final  int  position) {
        filelist da=mDatas. get (position);
        holder.tv.setText(da.getName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null){
                    /*注意参数*/
                    listener.OnItemClick(v, holder.getAdapterPosition(), mDatas.get(holder.getAdapterPosition()).getName());
                }
            }
        });
    }

    class  MyViewHolder extends RecyclerView.ViewHolder {
        TextView tv;
        TextView msg;
        View v;
        public  MyViewHolder(View view) {
            super(view);
            tv=(TextView) view.findViewById(R.id.txt_xs);
            v=view;
        }

    }

    public interface OnItemClickListener{
        /*注意参数*/
        public void OnItemClick(View v,int position,String id);
    }
    public void setOnItemClick(OnItemClickListener listener){
        this.listener=listener;
    }


}